package ooday04;



/**
 * @author Huangjin
 * @version 1.0
 * describe:
 * @date 2023/2/23 17:35
 */
public class Test {
    public static void main(String[] args) {
        //Animal o = new Animal();//抽象类不能被实例化
        //创建Animal数组对象，向上造型
        Animal[] animals = new Animal[5];
       animals[0] = new Dog("小黑",2 ,"黑");
       animals[1] = new Dog("小白",3,"白");
       animals[2] = new Fish("小金",3,"金");
       animals[3] = new Fish("小花",3,"白");
       animals[4] = new Chick("坤坤",2,"黄");
       //使用增强for循环遍历数组
       for (int i = 0;i< animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();

            if (animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();

            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEgg();
            }
            if (animals[i] instanceof Fish){
                Fish fish = (Fish) animals[i];

            }
            //接口判断
            if (animals[i] instanceof  Swim){
                Swim s = (Swim) animals[i];
                s.swim();
            }
        }
        Master master = new Master();
        Dog dog = new Dog("小黑",2,"黑");
        Fish fish = new Fish("小金",1,"金");
        Chick chick = new Chick("小花",2,"花");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);
    }
}
